﻿<%@ WebHandler Language="C#" Class="SubStorageCustList" %>

using System;
using System.Web;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Serialization;
using System.IO;
using XBase.Common;
using XBase.Model.Office.SubStoreManager;
using XBase.Business.Office.SubStoreManager;

public class SubStorageCustList : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            UserInfoUtil userInfo = (UserInfoUtil)SessionUtil.Session["UserInfo"];
            SubSellCustInfoModel model = new SubSellCustInfoModel();
            //设置行为参数
            int pageCount = 10;
            string orderString = context.Request.Form["orderby"].ToString();//排序
            string order = "asc";//排序：升序
            string orderBy = (!string.IsNullOrEmpty(orderString)) ? orderString.Substring(0, orderString.Length - 2) : "ID";//要排序的字段，如果为空，默认为"ID"
            if (orderString.EndsWith("_d"))
                order = "desc";//排序：降序
            pageCount = int.Parse(context.Request.Form["pageCount"].ToString());//每页显示记录数
            int pageIndex = int.Parse(context.Request.Form["pageIndex"].ToString());//当前页
            string myOrder = orderBy + " " + order;

            int TotalCount = 0;
            if (!string.IsNullOrEmpty(context.Request.Form["CustName"].ToString()))
            {
                model.CustName = context.Request.Form["CustName"].ToString();
            }
            if (!string.IsNullOrEmpty(context.Request.Form["CustAddr"].ToString()))
            {
                model.CustAddr = context.Request.Form["CustAddr"].ToString();
            }
            if (!string.IsNullOrEmpty(context.Request.Form["CustPhone"].ToString()))
            {
                model.CustMobile = context.Request.Form["CustPhone"].ToString();
            }
            if (!string.IsNullOrEmpty(context.Request.Form["CustTel"].ToString()))
            {
                model.CustTel = context.Request.Form["CustTel"].ToString();
            }
            model.DeptID = userInfo.DeptID.ToString();
            DataRow dr = SubStorageDBHelper.GetSubDeptFromDeptID(model.DeptID);
            if (dr != null)
            {
                model.DeptID = dr["ID"].ToString();
            }
            model.CompanyCD = userInfo.CompanyCD;
            DataTable dt = SubSellOrderBus.GetAllCustInfo(model, "list", pageIndex, pageCount, myOrder, ref TotalCount);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("{");
            sb.Append("totalCount:");
            sb.Append(TotalCount.ToString());
            sb.Append(",data:");
            if (dt.Rows.Count == 0)
                sb.Append("[{\"ID\":\"\"}]");
            else
                sb.Append(JsonClass.DataTable2Json(dt));
            sb.Append("}");
            context.Response.ContentType = "text/plain";
            context.Response.Write(sb.ToString());
            context.Response.End();
        }
        catch
        { }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}